/**
 * 
 */
package com.lvan.service;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * @author lvan.he<br>
 * 2013-7-15<br>
 * @version 1.0.0.0 
 */
public class Bb {
    private static Map<String, Map<String,String>> memData = new HashMap<String, Map<String,String>>();
    public static String getProperty(String field,String catName) {
        if(!memData.containsKey(catName)) {
            load(catName);
        }
        return memData.get(catName).get(field);
    }
    private static void load(String path) {
        memData = new HashMap<String, Map<String,String>>();
        String _path=Bb.class.getResource("/").getPath().replaceAll("%20", " ");
        _path = _path.substring(0, _path.indexOf("WEB-INF")) + path; 
        Properties p = new Properties();
        try {
            p.load(new FileInputStream(_path));
            Set<Object> set = p.keySet();
            Map<String,String> m = new HashMap<String, String>();
            for(Object o : set) {
                m.put(o.toString(), p.getProperty(o.toString()));
            }
            memData.put(path, m);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
